<template>
    <div class="template-form-Lu">
        <a-modal
            title="公务出差申请"
            :visible="applicationFormVisible"
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="100%"
            :dialog-style="{ margin: '0 auto' }"
            wrapClassName="applicationModal-form-fullmodal-Lu"
            @cancel="closeVisible">
            <div class="applicationModal-div-box-Lu">
                <div class="tabs-card-edit-box">
                    <a-tabs type="card" v-model:activeKey="summaryActiveKey" @change="summaryActiveChange">
                        <a-tab-pane key="申请表" tab="申请表"></a-tab-pane>
                        <a-tab-pane key="流转记录" tab="流转记录"></a-tab-pane>
                    </a-tabs>
                </div>
                <div  class="tab-box-v1">
                    <div v-if="summaryActiveKey == '申请表'" style="width: 80%;margin: 0 auto;padding-top: 30px;padding-bottom: 30px;">
                        <a-spin :spinning="spinning">
                            <a-button class="blue-btn" @click="printClick('出差',formState,qmImgList)" v-if="linkName == '我的已办'">打印</a-button>
                            <a-form :form="aform" ref="form" class="internalControl-reimbursement-model-form-box">
                                <a-descriptions bordered style="width: 100%;">
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='出差申请'">*</span>
                                            出差地点
                                        </span>
                                        <a-form-item ref="fccdd" prop="fccdd" class="zm-form-model">
                                            <a-textarea
                                                v-if="linkName=='出差申请' || linkName == '数据修订'"
                                                v-model="formState.fccdd"
                                                placeholder="出差地点:"
                                                :auto-size="{ minRows: 1}"
                                                v-decorator="[
                                                'fccdd', {initialValue:formState.fccdd,rules: rules.fccdd}]"
                                            />
                                            <span v-else>{{ formState.fccdd }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='出差申请'">*</span>
                                            出差开始时间
                                        </span>
                                        <a-form-item ref="fccksrq" prop="fccksrq" class="zm-form-model" style="min-width: 200px !important;">
                                            <a-input-group compact v-if="linkName=='出差申请' || linkName == '数据修订'">
                                                <a-date-picker
                                                    style="width: 60%"
                                                    v-model="formState.fccksrq"
                                                    type="date"
                                                    placeholder=""
                                                    v-decorator="[
                                                        'fccksrq', {initialValue:formState.fccksrq,rules: rules.fccksrq}]"
                                                    />
                                                <a-select
                                                    style="width: 40%"
                                                    default-value="08:00"
                                                    v-model="formState.fcckssj"
                                                    @change="getTime">
                                                    <a-select-option value="08:00">
                                                        08:00
                                                    </a-select-option>
                                                    <a-select-option value="12:00">
                                                        12:00
                                                    </a-select-option>
                                                    <a-select-option value="18:00">
                                                        18:00
                                                    </a-select-option>
                                                </a-select>
                                            </a-input-group>
                                            <span v-else>{{ moment(formState.fccksrq).format('YYYY-MM-DD') + ' ' +  formState.fcckssj}}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='出差申请'">*</span>
                                            出差结束时间
                                        </span>
                                        <a-form-item ref="fccjsrq" prop="fccjsrq" class="zm-form-model" style="min-width: 200px !important;">
                                            <a-input-group compact v-if="linkName=='出差申请' || linkName == '数据修订'">
                                                <a-date-picker
                                                    style="width: 60%"
                                                    v-model="formState.fccjsrq"
                                                    type="date"
                                                    placeholder=""
                                                    v-decorator="[
                                                        'fccjsrq', {initialValue:formState.fccjsrq,rules: rules.fccjsrq}]"
                                                />
                                                <a-select
                                                    style="width: 40%"
                                                    default-value="18:00"
                                                    v-model="formState.fccjssj"
                                                    @change="getTime">
                                                    <a-select-option value="08:00">
                                                        08:00
                                                    </a-select-option>
                                                    <a-select-option value="12:00">
                                                        12:00
                                                    </a-select-option>
                                                    <a-select-option value="18:00">
                                                        18:00
                                                    </a-select-option>
                                                </a-select>
                                            </a-input-group>
                                            <span v-else>{{ moment(formState.fccjsrq).format('YYYY-MM-DD')+ ' ' +  formState.fccjssj}}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="2">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='出差申请'">*</span>
                                            出差事由
                                        </span>
                                        <a-form-item ref="fccsy" prop="fccsy" class="zm-form-model">
                                            <a-textarea
                                                v-if="linkName=='出差申请' || linkName == '数据修订'"
                                                v-model="formState.fccsy"
                                                placeholder="请输入出差事由:"
                                                :auto-size="{ minRows: 2}"
                                                v-decorator="[
                                                    'fccsy', {initialValue:formState.fccsy,rules: rules.fccsy}]"
                                            />
                                            <span v-else>{{ formState.fccsy }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            是否派车
                                        </span>
                                        <a-form-item ref="fccsy" prop="fccsy" class="zm-form-model">
                                            <a-radio-group
                                                v-if="linkName=='出差申请' || linkName == '数据修订'"
                                                v-model="formState.fsfpc"
                                                name="radioGroup"
                                                default-value="否"
                                                >
                                                <a-radio value="是">
                                                    是
                                                </a-radio>
                                                <a-radio value="否">
                                                    否
                                                </a-radio>
                                            </a-radio-group>
                                            <span v-else>{{ formState.fsfpc }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="formState.fsfpc == '是'?2:3">
                                        <span slot="label" class="descriptions-label-slot">
                                            同行人员
                                        </span>
                                        <a-form-item ref="fccsy" prop="fccsy" class="zm-form-model">
                                            <a-input
                                                v-if="linkName=='出差申请' || linkName == '数据修订'"
                                                :defaultValue="formState.fcctxryxm"
                                                v-model="formState.fcctxryxm"
                                                placeholder="请选择出差同行人员"
                                                @click="selectPeers">
                                            </a-input>
                                            <!-- <a-select
                                                v-if="linkName=='出差申请' || linkName == '数据修订'"
                                                mode="tags"
                                                placeholder="请选择出差同行人员"
                                                v-model="formState.fcctxryid"
                                                style="width: 200px"
                                                @change="handleChange"
                                                >
                                                <a-select-option v-for="(item,index) in peersList" :key="index" :value="item.userId">
                                                    {{ item.userName }}
                                                </a-select-option>
                                            </a-select> -->
                                            <span v-else>{{ (formState.fcctxryxm && formState.fcctxryxm.length)?formState.fcctxryxm:'无同行人员' }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item v-if="formState.fsfpc == '是'">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='出差申请'">*</span>
                                            派遣车辆
                                        </span>
                                        <a-form-item ref="fccsy" prop="fccsy" class="zm-form-model">
                                            <a-radio-group
                                                v-if="linkName=='出差申请' || linkName == '数据修订'"
                                                v-model="formState.fcph"
                                                name="radioGroup"
                                                v-decorator="[
                                                        'fcph', {initialValue:formState.fcph,rules: rules.fcph}]"
                                                >
                                                <a-radio value=" 桂AS9027">
                                                    桂AS9027
                                                </a-radio>
                                                <a-radio value="桂AWL956">
                                                    桂AWL956
                                                </a-radio>
                                            </a-radio-group>
                                            <span v-else>{{ formState.fcph }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('科室审核').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('科室审核').hjmc">*</span>
                                            本科（室）<br/>领导意见
                                        </span>
                                        <a-form-item ref="fksldyj" prop="fksldyj" class="zm-form-model">
                                            <div style="width: 100%;" v-for="(item,index) in formState.fksldryjs" :key="index">
                                                <p>{{ formState.fksldryjs[index] }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrlById(formState.fksldrids[index])" :src="getUrlById(formState.fksldrids[index])" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fksldrs[index] }}</span>
                                                    <span>{{ formState.fksldryjsjs[index] }}</span>
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-if="(descriptionsData('科室审核').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffksldyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('OA出差',formState.fksldyj,'fksldyj')"
                                                    v-decorator="[
                                                        'fksldyj', { initialValue:formState.fksldyj, rules: rules.fksldyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fksldyjsj)"
                                                        :default-value="moment(formState.fksldyjsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fksldyjsj')"
                                                    />
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('办公室审核').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('办公室审核').hjmc">*</span>
                                            办公室<br/>派车意见
                                        </span>
                                        <a-form-item ref="fbgspcyj" prop="fbgspcyj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('办公室审核').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffbgspcyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('OA出差',formState.fbgspcyj,'fbgspcyj')"
                                                    v-decorator="[
                                                        'fbgspcyj', { initialValue:formState.fbgspcyj, rules: rules.fbgspcyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fbgspcyjsj)"
                                                        :default-value="moment(formState.fbgspcyjsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fbgspcyjsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fbgspcyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('办公室审核')" :src="getUrl('办公室审核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fbgspcyjr }}</span>
                                                    <span>{{ formState.fbgspcyjsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('中心分管领导审核').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('中心分管领导审核').hjmc">*</span>
                                            中心分管<br/>领导意见
                                        </span>
                                        <a-form-item ref="fzxfgldyj" prop="fzxfgldyj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('中心分管领导审核').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffzxfgldyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('OA出差',formState.fzxfgldyj,'fzxfgldyj')"
                                                    v-decorator="[
                                                        'fzxfgldyj', { initialValue:formState.fzxfgldyj, rules: rules.fzxfgldyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fzxfgldyjsj)"
                                                        :default-value="moment(formState.fzxfgldyjsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fzxfgldyjsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fzxfgldyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('中心分管领导审核')" :src="getUrl('中心分管领导审核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fzxfgldyjr }}</span>
                                                    <span>{{ formState.fzxfgldyjsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('中心领导审核').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('中心领导审核').hjmc">*</span>
                                            中心主要<br/>领导意见
                                        </span>
                                        <a-form-item ref="fzxzyldyj" prop="fzxzyldyj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('中心领导审核').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffzxzyldyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('OA出差',formState.fzxzyldyj,'fzxzyldyj')"
                                                    v-decorator="[
                                                        'fzxzyldyj', { initialValue:formState.fzxzyldyj, rules: rules.fzxzyldyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fzxzyldyjsj)"
                                                        :default-value="moment(formState.fzxzyldyjsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fzxzyldyjsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fzxzyldyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('中心领导审核')" :src="getUrl('中心领导审核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fzxzyldyjr }}</span>
                                                    <span>{{ formState.fzxzyldyjsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                </a-descriptions>
                            </a-form>
                        </a-spin>
                    </div>
                    <div v-if="summaryActiveKey == '流转记录'" style="padding-top: 30px;">
                        <transferRecords
                            ref="transferRecordsRef"
                            :config="circulationDataTableConfig"
                            @getCirculationQmImg="getCirculationQmImg"/>
                    </div>
                </div>
            </div>
            <template slot="footer">
                <div v-if="linkName == '我的已办'">
                    <a-button class="blue-btn" @click="closeVisible">关闭</a-button>
                </div>
                <div v-else-if="linkName == '数据修订'">
                    <a-button class="blue-btn" @click="updataData">确认修订</a-button>
                </div>
                <div v-else>
                    <a-button @click="onSave('保存')">
                        保存
                    </a-button>
                    <a-button class="blue-btn" @click="onSubmit('提交')">
                        提交
                    </a-button>
                    <a-button v-if="linkName !== '出差申请'" class="red-btn" @click="returnClick">
                        退回
                    </a-button>
                </div>
            </template>
        </a-modal>
        <printModal ref="printModalRef" />
        <personnelList ref="personnelListRef" @checkPersonnel="checkPersonnel" :modaObj="{place: ''}" />
    </div>
</template>
<script>
import {
    editFuntion,
    initBzFlow,
    saveFlow,
    submitFlow,
    queryJobByJobId,
    returnUpperzdyFlowJob,
    getMoreUserSignLinkList,
    pidgetlchj,
    getBmUser,
    getBmUserxd,
} from './service/index'
import assessCheckApi from './service/api.js'
import transferRecords from '../modal/transferRecords'
import personnelList from '../modal/personnelList'
import printModal from '../modal/printModal'
import moment from 'moment'
export default {
    components: {
        transferRecords,
        personnelList,
        printModal
    },
    data() {
        return {
            moment:moment,
            applicationFormVisible: false,
            summaryActiveKey: '申请表',
            aform:this.$form.createForm(this, { name: 'aform' }),
            formState: {
                fccjssj: "18:00",
                fcckssj: "08:00",
                fsfpc: '否'
            },
            circulationDataTableConfig: {
                api: assessCheckApi.flowJkPage,
                rowId: 'id',
                urlType: true,
                paramet:{
                    oaid: ''
                }
            },
            rules:{
                fccdd: [{
                    required: true,
                    message: '请输入出差地点',
                    trigger: 'blur',
                }],
                fccksrq: [{
                    type: 'object',
                    required: true,
                    message: '请选择出差开始时间',
                    trigger: 'blur',
                }],
                fccjsrq: [{
                    type: 'object',
                    required: true,
                    message: '请选择出差结束时间',
                    trigger: 'blur',
                }],
                fccsy: [{
                    required: true,
                    message: '请输入出差事由',
                    trigger: 'blur',
                }],
                fcph: [{
                    required: true,
                    message: '请选择车辆',
                    trigger: 'blur',
                }],
                fksldyj: [
                    { required: true, message: '请输入本科（室）意见', trigger: 'blur' }
                ],
                fbgspcyj: [
                    { required: true, message: '请输入办公室意见', trigger: 'blur' }
                ],
                fzxfgldyj: [
                    { required: true, message: '请输入中心分管领导意见', trigger: 'blur' }
                ],
                fzxzyldyj: [
                    { required: true, message: '请输入中心主要领导意见', trigger: 'blur' }
                ],
            },
            qmImgList: [],
            displayList: [],
            peersList: [],
            linkName: '出差申请',
            spinning: false,
        }
    },
    mounted() {
        // this.circulationDataTableConfig.paramet.oaid = '96db3fccad0245df878468d4339f9e5e'
        this.$refs.reviewOpinionsRef= Date.now()
    },
    methods: {
        getInitData(){
            this.formState = {}
            this.formState = {
                fccjssj: "18:00",
                fcckssj: "08:00",
                fsfpc: '否'
            }
            this.getgetBmUser()
        },
        getData(val){
            if(val){
                this.linkName = val.hjmc
                this.formState = {}
                this.formState = {
                    ...val.oaMap,
                    jobid: val.jobMap?val.jobMap.id:''
                }
                this.formState.fccksrq = val.oaMap.fccksrq?moment(val.oaMap.fccksrq):null
                this.formState.fccjsrq = val.oaMap.fccjsrq?moment(val.oaMap.fccjsrq):null
                this.formState.fksldryjs = val.oaMap.fksldryjs?val.oaMap.fksldryjs.split('@@'):[]
                this.formState.fksldrs = val.oaMap.fksldrs?val.oaMap.fksldrs.split('@@'):[]
                this.formState.fksldryjsjs = val.oaMap.fksldryjsjs?val.oaMap.fksldryjsjs.split('@@'):[]
                this.formState.fksldrids = val.oaMap.fksldrids?val.oaMap.fksldrids.split('@@'):[]
                // this.formState.fcctxryid = val.oaMap.fcctxryid?val.oaMap.fcctxryid.split(','):[]
                this.circulationDataTableConfig.paramet.oaid = this.formState.id
                this.qmImgList = []
                this.displayList = []
                this.getDisplayList()
                if(this.linkName == '数据修订'){
                    this.getgetBmUserxd()
                } else {
                    this.getgetBmUser()
                }
            }
        },
        getDisplayList(){
            pidgetlchj({pid:this.formState.id}).then((res) => {
                let arr1 = res.result
                this.displayList = []
                this.displayList = res.result

                if(this.linkName == '数据修订'){
                    const index = this.displayList.findIndex((item) => item.blzt == '待办');
                    if (index !== -1) {
                        this.displayList.splice(index, 1);
                    }
                    //console.log('this.displayList',this.displayList)
                }

                arr1.forEach(async item => {
                    if(item.blrid && item.blzt!=='待办'){
                        let resa = await getMoreUserSignLinkList({ids:item.blrid})
                        if(resa.success && resa.result.length){
                            resa.result.forEach((itemb,indexb) => {
                                if(itemb.signLink == ''){
                                    this.qmImgList.push({
                                        hjmc: item.hjmc,
                                        blrid: itemb.userid,
                                        url: null
                                    })
                                } else {
                                    this.qmImgList.push({
                                        hjmc: item.hjmc,
                                        blrid: itemb.userid,
                                        url: itemb.signLink+'&aa='+Date.now()
                                    })
                                }
                            })
                            // if(resa.result[0].signLink == ''){
                            //     // //console.log('没有获得图片 signLink == 0')
                            //     this.qmImgList.push({
                            //         hjmc: item.hjmc,
                            //         blrid: item.blrid,
                            //         url: null
                            //     })
                            // } else {
                            //     this.qmImgList.push({
                            //         hjmc: item.hjmc,
                            //         blrid: item.blrid,
                            //         url: resa.result[0].signLink+'&aa='+Date.now()
                            //     })
                            //     // //console.log('获得的签名图片列表',this.qmImgList)
                            // }
                        } else {
                            // //console.log('没有获得图片')
                        }
                    } else {}
                })
                //console.log('最终获得的签名图片列表---',this.qmImgList)
            })
        },
        getgetBmUser(){
            getBmUser().then(res => {
                this.peersList = []
                this.peersList = res.result
            })
        },
        getgetBmUserxd(){
            getBmUserxd({oaid: this.formState.id}).then(res => {
                this.peersList = []
                this.peersList = res.result
            })
        },
        handleChange(value) {
            //console.log(`Selected: ${value}`);
            this.formState.fcctxryid = value
            let nameStr = ''
            this.peersList.forEach(item => {
                if(value.indexOf(item.userId) !== -1){
                    nameStr = nameStr + item.userName + ' '
                }
            })
            this.formState.fcctxryxm = nameStr
            //console.log(this.peersList)
            //console.log(this.formState.fcctxryxm)
            //console.log(this.formState.fcctxryid)
        },
        selectPeers(){
            this.$refs.personnelListRef.personnelListVisible = true
            this.$refs.personnelListRef.getData({place:'',oldId:this.formState.fcctxryid?this.formState.fcctxryid.split(','):[]})
        },
        checkPersonnel(val,list,list2){
            //console.log(val,list,list2)
            let data = {
                fcctxryxm: list2.toString(),
                fcctxryid: list.toString()
            }
            this.formState = {...this.formState,...data}
            // this.formState.fcctxryxm = list2.toString()
            // this.formState.fcctxryid = list.toString()
            this.aform.setFieldsValue({
                fcctxryxm: this.formState.fcctxryxm,
                fcctxryid: this.formState.fcctxryid,
            });
            //console.log('========',this.formState)
            //console.log('========',this.aform)
        },
        closeVisible(){
            this.applicationFormVisible = false
            this.$emit('success')
        },
        summaryActiveChange(val){
            //console.log(val)
        },
        date1Change(val){
            this.formState.fccksrq = val
            this.getTime()
        },
        date2Change(val){
            this.formState.fccjsrq = val
            this.getTime()
        },
        getTime(){
            if(this.formState.fccksrq !== null && this.formState.fccjsrq !== null){
                let startTime = new Date(Date.parse(moment(this.formState.fccksrq).format('YYYY-MM-DD') + ' ' + this.formState.fcckssj)).getTime()
                let ensTime = new Date(Date.parse(moment(this.formState.fccjsrq).format('YYYY-MM-DD') + ' ' + this.formState.fccjssj)).getTime()
                if(startTime >= ensTime){
                    this.$message.warning('当前时间选择无效，出差开始时间需大于出差结束时间，请重新选择')
                }
            }
        },
        getCirculationQmImg(item1,item2){
            //console.log('-----?????-----',item1,item2)
            this.qmImgList = []
            this.displayList = []
            this.qmImgList = item1
            this.displayList = [...item2]
            //console.log('111111111',this.qmImgList)
            //console.log('222222222',this.displayList)
        },
        getUrl(hjmcName){
            let url = ''
            this.qmImgList.forEach(item => {
                if(item.hjmc == hjmcName){
                    url = item.url
                }
            })
            return url
        },
        getUrlById(ids){
            let url = ''
            this.qmImgList.forEach(item => {
                if(item.blrid == ids){
                    url = item.url
                }
            })
            return url
        },
        descriptionsData(hjmc){
            let data = {}
            this.displayList.forEach(item => {
                if(item.hjmc == hjmc){
                    data = {...item}
                }
            })
            return data
        },
        getInputOpinion(val,valueData){
            //console.log(val,valueData)
            let data = this.formState
            data[valueData.hjmc] = val
            this.aform.setFieldsValue({
                fksldyj: this.formState.fksldyj,
                fbgspcyj: this.formState.fbgspcyj,
                fzxfgldyj: this.formState.fzxfgldyj,
                fzxzyldyj: this.formState.fzxzyldyj
            });
        },
        opinions(val1,val2,val3){
            //console.log(val1,val2,val3)
            this.$refs[`reviewOpinionsRef${val3}`].getData({opinionType:val1,oldVal:val2,valueData:{hjmc:val3}})
        },
        onSave(){
            let data = {}
            let sdata = {
                jobid: this.formState.jobid,
                oaid: this.formState.id,
                map: {},
                opinion: '',
            }
            if(this.linkName == '出差申请'){
                data = {
                    fccdd: this.formState.fccdd,
                    fccsy: this.formState.fccsy,
                    fsfpc: this.formState.fsfpc,
                    fcph: this.formState.fcph,
                    fccksrq: this.formState.fccksrq?moment(this.formState.fccksrq).format('YYYY-MM-DD'):null,
                    fcckssj: this.formState.fcckssj,
                    fccjsrq: this.formState.fccjsrq?moment(this.formState.fccjsrq).format('YYYY-MM-DD'):null,
                    fccjssj: this.formState.fccjssj,
                    fcctxryxm: this.formState.fcctxryxm,
                    fcctxryid: this.formState.fcctxryid?this.formState.fcctxryid.toString():null,
                    id: this.formState.id?this.formState.id:''
                }
                sdata.map = {
                    ...data
                }
                this.formState.id?this.saveFlowFuntion(sdata):this.initBzFlowFuntion(data)
            } else if(this.linkName == '科室审核'){
                sdata.map = {
                    fksldyj: this.formState.fksldyj,
                    fksldyjr: this.formState.fksldyjr,
                    fksldyjsj: this.formState.fksldyjsj
                }
                sdata.opinion = this.formState.fksldyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '办公室审核'){
                sdata.map = {
                    fbgspcyj: this.formState.fbgspcyj,
                    fbgspcyjr: this.formState.fbgspcyjr,
                    fbgspcyjsj: this.formState.fbgspcyjsj
                }
                sdata.opinion = this.formState.fbgspcyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '中心分管领导审核'){
                sdata.map = {
                    fzxfgldyj: this.formState.fzxfgldyj,
                    fzxfgldyjr: this.formState.fzxfgldyjr,
                    fzxfgldyjsj: this.formState.fzxfgldyjsj
                }
                sdata.opinion = this.formState.fzxfgldyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '中心领导审核'){
                sdata.map = {
                    fzxzyldyj: this.formState.fzxzyldyj,
                    fzxzyldyjr: this.formState.fzxzyldyjr,
                    fzxzyldyjsj: this.formState.fzxzyldyjsj,
                }
                sdata.opinion = this.formState.fzxzyldyj,
                this.saveFlowFuntion(sdata)
            }
        },
        onSubmit(){
            this.aform.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要提交吗?',
                        onOk() {
                            let data = {
                                jobid: that.formState.jobid,
                                oaid: that.formState.id,
                                map: {},
                                opinion: '',
                            }
                            if(that.linkName == '出差申请'){
                                data.map = {
                                    fccdd: that.formState.fccdd,
                                    fccsy: that.formState.fccsy,
                                    fsfpc: that.formState.fsfpc,
                                    fcph: that.formState.fcph,
                                    fccksrq: that.formState.fccksrq?moment(that.formState.fccksrq).format('YYYY-MM-DD'):null,
                                    fcckssj: that.formState.fcckssj,
                                    fccjsrq: that.formState.fccjsrq?moment(that.formState.fccjsrq).format('YYYY-MM-DD'):null,
                                    fccjssj: that.formState.fccjssj,
                                    fcctxryxm: that.formState.fcctxryxm,
                                    fcctxryid: that.formState.fcctxryid?that.formState.fcctxryid.toString():null,
                                    id: that.formState.id?that.formState.id:'',
                                    fsffqlc: that.formState.id?'':'是',
                                }
                                that.formState.id?that.submitFlowFuntion(data):that.initBzFlowFuntion(data.map,'1')
                            } else if(that.linkName == '科室审核'){
                                data.map = {
                                    fksldyj: that.formState.fksldyj,
                                    fksldyjr: that.formState.fksldyjr,
                                    fksldyjsj: that.formState.fksldyjsj
                                }
                                data.opinion = that.formState.fksldyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '办公室审核'){
                                data.map = {
                                    fbgspcyj: that.formState.fbgspcyj,
                                    fbgspcyjr: that.formState.fbgspcyjr,
                                    fbgspcyjsj: that.formState.fbgspcyjsj
                                }
                                data.opinion = that.formState.fbgspcyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '中心分管领导审核'){
                                data.map = {
                                    fzxfgldyj: that.formState.fzxfgldyj,
                                    fzxfgldyjr: that.formState.fzxfgldyjr,
                                    fzxfgldyjsj: that.formState.fzxfgldyjsj
                                }
                                data.opinion = that.formState.fzxfgldyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '中心领导审核'){
                                data.map = {
                                    fzxzyldyj: that.formState.fzxzyldyj,
                                    fzxzyldyjr: that.formState.fzxzyldyjr,
                                    fzxzyldyjsj: that.formState.fzxzyldyjsj,
                                }
                                data.opinion = that.formState.fzxzyldyj,
                                that.submitFlowFuntion(data)
                            }
                        },
                        onCancel() {},
                    });
                }
            })
        },
        initBzFlowFuntion(data,type){
            initBzFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.formState = {}
                    this.formState = {
                        ...res.result.nkMap,
                        jobid: res.result.jobMap.id
                    }
                    this.formState.fccksrq = this.formState.fccksrq?moment(this.formState.fccksrq):null
                    this.formState.fccjsrq = this.formState.fccjsrq?moment(this.formState.fccjsrq):null
                    this.formState.fcctxryid = this.formState.fcctxryid?this.formState.fcctxryid.split(','):[]

                    if(type){
                        this.closeVisible()
                    }
                } else {
                    this.$message.warning(res.message)
                }
                this.loading = false
            })
        },
        saveFlowFuntion(data){
            this.spinning = true
            saveFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        submitFlowFuntion(data){
            this.spinning = true
            submitFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        // 退回
        returnClick(){
            this.aform.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要退回吗?',
                        onOk() {
                            that.spinning = true
                            queryJobByJobId({jobid:that.formState.jobid}).then(res => {
                                let list = res.result.jobHistoryList
                                let slist = list.filter(item => item.fhjmc == '出差申请')
                                const sortedDates = slist.sort((a, b) => new Date(b) - new Date(a));
                                that.returnFuntion(that.formState.jobid,sortedDates[slist.length - 1].id)
                            })
                        },
                        onCancel() {},
                    })
                }
            })
        },
        returnFuntion(jobid,ids){
            let returnStr = ''
            if(this.linkName == '科室审核'){
                returnStr = this.formState.fksldyj
            } else if(this.linkName == '办公室审核'){
                returnStr = this.formState.fbgspcyj
            } else if(this.linkName == '中心分管领导审核'){
                returnStr = this.formState.fzxfgldyj
            } else if(this.linkName == '中心领导审核'){
                returnStr = this.formState.fzxzyldyj
            }
            let data = {
                jobid: jobid,
                opinion: returnStr,
                shjid: ids,
                lcmbbm: '',
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.error(res.message)
                }
                this.spinning = false
            })
        },
        printClick(type,value,qmValue){
            this.$refs.printModalRef.modalClick(type,value,qmValue)
        },
        yjTimeChange(val,name){
            let data = this.formState
            data[name] = moment(val).format('YYYY-MM-DD HH:mm:ss')
        },
        updataData(){
            var that = this
            that.$confirm({
                title: '您确定修改当前表单数据吗?',
                onOk() {
                    let data = {
                        id: that.formState.id,
                        fccdd: that.formState.fccdd,
                        fccsy: that.formState.fccsy,
                        fccksrq: moment(that.formState.fccksrq).format('YYYY-MM-DD'),
                        fcckssj: that.formState.fcckssj,
                        fccjsrq: moment(that.formState.fccjsrq).format('YYYY-MM-DD'),
                        fccjssj: that.formState.fccjssj,
                        fcctxryxm: that.formState.fcctxryxm,
                        fcctxryid: that.formState.fcctxryid?that.formState.fcctxryid.toString():null,
                        fksldyj: that.formState.fksldyj,
                        fksldyjr: that.formState.fksldyjr,
                        fksldyjsj: that.formState.fksldyjsj,
                        fbgspcyj: that.formState.fbgspcyj,
                        fbgspcyjr: that.formState.fbgspcyjr,
                        fbgspcyjsj: that.formState.fbgspcyjsj,
                        fzxfgldyj: that.formState.fzxfgldyj,
                        fzxfgldyjr: that.formState.fzxfgldyjr,
                        fzxfgldyjsj: that.formState.fzxfgldyjsj,
                        fzxzyldyj: that.formState.fzxzyldyj,
                        fzxzyldyjr: that.formState.fzxzyldyjr,
                        fzxzyldyjsj: that.formState.fzxzyldyjsj,
                    }
                    //console.log(data)
                    that.spinning = true
                    editFuntion(data).then(res => {
                        if(res.code == 200){
                            that.$message.success(res.message)
                        } else {
                            that.$message.warning(res.message)
                        }
                        that.spinning = false
                    })
                },
                onCancel() {
                    //console.log('Cancel');
                },
            });
        },
    }
}
</script>
<style>
@import url('../css/oaLess.css');
</style>
